package com.android.plc.ui.control;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.android.plc.CONST;
import com.android.plc.CONST.COMMAND;
import com.android.plc.R;

public class DimControl extends NormalControl implements OnSeekBarChangeListener
{
	private static final String TAG = "NormalControl";
	public ImageButton mOnBtn;
	public ImageButton mOffBtn;
	public SeekBar mLight;

	public DimControl(Context context, ViewGroup view)
	{
		super(context, view, R.layout.control_dim);
	}

	@Override
	public void initView(ViewGroup view)
	{
		super.initView(view);
		mLight = (SeekBar) view.findViewById(R.id.seek_light);
		mLight.setMax(100);
		mLight.setOnSeekBarChangeListener(this);
		sendCommand(COMMAND.STATUSREQ, 0, 0);
	}
	
	@Override
	public void onClick(View v)
	{
		super.onClick(v);
		sendCommandDelay(COMMAND.STATUSREQ, 0, 0);
	}
	
	@Override
	public void onReceive(int command, int data1, int data2)
	{
		super.onReceive(command, data1, data2);
		if (command == COMMAND.OFF)
		{
			Log.w(TAG, "rev socket COMMAND.OFF");
			mLight.setProgress(0);
		} else if (command == COMMAND.PRESETDIM || command == COMMAND.STATUSON || command == COMMAND.STATUSOFF)
		{
			mLight.setProgress(data1);
		}
	}

	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
	{
		// sendCommand(COMMAND.PRESETDIM, progress,
		// CONST.LIGHT_DIMMER_FADE_RATE);
	}

	public void onStartTrackingTouch(SeekBar seekBar)
	{

	}

	public void onStopTrackingTouch(SeekBar seekBar)
	{
		sendCommand(COMMAND.PRESETDIM, seekBar.getProgress(), CONST.LIGHT_DIMMER_FADE_RATE);
		sendCommandDelay(COMMAND.STATUSREQ, 0, 0);
	}
}
